/*************************************************************************
	> File Name: inter.h
	> Author: ma6174
	> Mail: ma6174@163.com 
	> Created Time: 2021年12月12日 星期日 15时57分34秒
 ************************************************************************/

#include<iostream>
#include <string>

//演奏内容类
class PlayContext
{
public:
	PlayContext() = default;
	PlayContext(std::string t) : text(t) {}

	void setText(std::string t)
	{
		text = t;
	}

	std::string getText()
	{
		return text;
	}

private:
	std::string text;
};

//表达式抽象类
struct Expression
{
	void interpret(PlayContext* context)
	{
		if (context->getText().length() == 0)
			return;
		else
		{
			std::string s = "";
			char playKey = context->getText()[0];
			if (context->getText().length() > 2)
			{
				std::string s = context->getText().substr(2);
				int playValue = int(std::stod(s.substr(0, s.find_first_of(" "))) + 0.5);
				context->setText(s.substr(s.find_first_of(" ") + 1));

				execute(playKey, playValue);
			}
			else
				context->setText(s);
		}
	}

	virtual void execute(char key, int value) = 0;
};

//音符类－表达式具体类
struct Note : public Expression
{
	virtual void execute(char key, int value)
	{
		std::string note = "";
		switch (key)
		{
			case 'C':
				note = "1";
				break;
			case 'D':
				note = "2";
				break;
			case 'E':
				note = "3";
				break;
			case 'F':
				note = "4";
				break;
			case 'G':
				note = "5";
				break;
			case 'A':
				note = "6";
				break;
			case 'B':
				note = "7";
				break;
		}
		std::cout << note << " ";
	}
};

struct Scale : public Expression
{
	virtual void execute(char key, int value)
	{
		std::string scale = "";
		switch (value)
		{
			case 1:
				scale = "低音";
				break;
			case 2:
				scale = "中音";
				break;
			case 3:
				scale = "高音";
				break;
		}
		std::cout << scale << " ";
	}
};

struct Speed : public Expression
{
	virtual void execute(char key, int value)
	{
		std::string speed = "";
		if (value < 500)
			speed = "快速";
		else if (value >= 1000)
			speed = "慢速";
		else
			speed = "中速";
		std::cout << speed << " ";
	}
};
